import React, { Component } from 'react'

export default class App extends Component {
  constructor (props) {
    super(props)
    this.state = {
      name: 'React',
      isLiked: false
    }
  }
  render() {
    return (
      <div>
        <div>欢迎来到 { this.state.name } 的世界</div>
        <button onClick = { () => {
          // prevState代表的就是上一次的状态
          this.setState((prevState, props) => {
            return {
              isLiked: !prevState.isLiked
            }
          }, () => {
            // 状态一定被修改完毕
          })
        } }>切换</button>
        { this.state.isLiked ? '喜欢' : '不喜欢'}
      </div>
    )
  }
}
